package com.slaffka.action;

import com.slaffka.report.Report;
import net.sf.jasperreports.engine.JasperPrint;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: slaffka
 * Date: 19.11.12
 * Time: 21:59
 * To change this template use File | Settings | File Templates.
 */
@Stateless
@Named("reportAction")
public class ReportAction implements Serializable {

    private List<Report> reportList;
    private Report currentReport;

    /**
     * Информация о выполненном отчёте сохраняется
     */
    private JasperPrint currentJasperPrint;

    public List<Report> getReportList() {
        if (reportList == null){
            reportList = new ArrayList<Report>();
            reportList.add(new Report(1L, "Прибыль", "report"));
            reportList.add(new Report(2L, "Прибыль1", "report1"));
            reportList.add(new Report(3L, "Пользователи", "report3"));
        }
        return reportList;
    }

    public void setReportList(List<Report> reportList) {
        this.reportList = reportList;
    }

    public Report getCurrentReport() {
        if (currentReport == null){
            currentReport = reportList.get(0);
        }
        return currentReport;
    }

    public void setCurrentReport(Report currentReport) {
        this.currentReport = currentReport;
    }

    public boolean isCurrentReport(Long reportId){
        boolean isCurrentRep = getCurrentReport().getReportId().equals(reportId);
        return isCurrentRep;
    }

    public JasperPrint getCurrentJasperPrint() {
        return currentJasperPrint;
    }

    public void setCurrentJasperPrint(JasperPrint currentJasperPrint) {
        this.currentJasperPrint = currentJasperPrint;
    }
}
